package com.dnb.webmash.playmaker.client.playertypes;

import com.dnb.webmash.playmaker.client.ClientFieldVerifier;
import com.dnb.webmash.playmaker.client.mediaplayer.MediaPlayer;
import com.dnb.webmash.playmaker.shared.PlayerType;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;

//universal x-shockwave-flash media embedder
public class FlashPlayer extends MediaPlayer{
	
	public FlashPlayer() {
		myType = PlayerType.FLASH;
		setElement(Document.get().createObjectElement());
		myElement = Document.get().createElement("embed");
	}		
	@Override
	protected void embed() {
		if (ClientFieldVerifier.isValidURL(this.mediaIt.getFullURL())){			
			appendEmbedFlashElement();
			appendRelatedParameters();
		}
	}
	private void appendEmbedFlashElement() {
		myElement.setAttribute("src", mediaIt.getFullURL());
		myElement.setAttribute("type", "application/x-shockwave-flash");		
		myElement.setAttribute("allowScriptAccess", "always");
		getElement().appendChild(myElement);
	}
	private void appendRelatedParameters() {		
		Element paramElement = Document.get().createElement("param");
		paramElement.setAttribute("name", "allowFullScreen");
		paramElement.setAttribute("value", "true");
		getElement().appendChild(paramElement);
		
		paramElement = Document.get().createElement("param");
		paramElement.setAttribute("allowScriptAccess", "always");
		getElement().appendChild(paramElement);
	}
}
